package com.freesky.web.manager.controller;

import com.freesky.common.dao.entity.Express;
import com.freesky.common.pojo.DataTablesResult;
import com.freesky.common.utils.reponse.JSONResponse;
import com.freesky.web.manager.remote.order.ExpressRemote;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author Freesky
 */
@Controller
@Api(description = "快递")
@RequestMapping("/express")
public class ExpressController {

    @Autowired
    private ExpressRemote expressRemote;

    @GetMapping("/page")
    public String page() {
        return "express/list";
    }

    @GetMapping("/update/page")
    public String update() {
        return "express/update";
    }

    @GetMapping("/add/page")
    public String add() {
        return "express/add";
    }

    @ResponseBody
    @GetMapping(value = "/list")
    @ApiOperation(value = "获得所有快递")
    public DataTablesResult addressList() {
        return expressRemote.addressList();
    }

    @ResponseBody
    @PutMapping(value = "/add")
    @ApiOperation(value = "添加快递")
    public JSONResponse addExpress(@ModelAttribute Express express) {

        return expressRemote.addExpress(express);
    }

    @ResponseBody
    @PostMapping(value = "/update")
    @ApiOperation(value = "编辑快递")
    public JSONResponse updateAddress(@ModelAttribute Express express) {
        return expressRemote.updateAddress(express);
    }

    @ResponseBody
    @DeleteMapping(value = "/del/{ids}")
    @ApiOperation(value = "删除快递")
    public JSONResponse delAddress(@PathVariable(value = "ids") int[] ids) {
        return expressRemote.delAddress(ids);
    }
}
